package com.company;

import java.util.Scanner;

public class Game {
    private Room currentRoom;
    public Game()
    {
        createRooms();
    }
    private void createRooms()
    {
        Room enter, rooma, roomb, roomc, roomd,roome;
        enter = new Room("地宫入口");
        rooma = new Room("一号房");
        roomb = new Room("二号房");
        roomc = new Room("三号房");
        roomd = new Room("四号房");
        roome = new Room("抉择房");
        enter.setExit("金门",rooma);
        enter.setExit("银门",roomc);
        enter.setExit("铁门",roomb);
        rooma.setExit("金门", enter);
        roomc.setExit("木门",enter);
        roomc.setExit("银门",roomd);
        roomd.setExit("铁门",roomc);
        roomb.setExit("次元门",roome);
        roome.setExit("寻找更多地机遇",rooma);
        roome.setExit("收手 say bye",enter);
        currentRoom = enter;
    }
    private void printWelcome() {
        System.out.println();
        System.out.println("欢迎来到地下城！");
        System.out.println("这里用无尽的宝藏和更多地危险，来吧，用你的贪欲来征服这里，或者…… ");
        System.out.println("当你困惑的时候，请大喊 '帮帮我' 。或许，或许会有其他冒险者来帮助你");
        System.out.println();
        System.out.println("现在你在" + currentRoom);
        System.out.print("在你面前有：\n");
        System.out.print(currentRoom.getExitdesc());
    }
    private void printHelp()
    {
        System.out.print("迷路了吗？你可以进入一扇门，或者说别了您内");
        System.out.println("如：\t进入 金门");
    }
    private void goRoom(String direction)
    {
        Room nextRoom = null;
        if(direction.equals("木门")) {
            nextRoom = currentRoom.getExit("木门");
        }
        if(direction.equals("金门")) {
            nextRoom = currentRoom.getExit("金门");
        }
        if(direction.equals("银门")) {
            nextRoom = currentRoom.getExit("银门");
        }
        if(direction.equals("铁门")) {
            nextRoom = currentRoom.getExit("铁门");
        }
        if(direction.equals("次元门")){
            nextRoom = currentRoom.getExit("次元门");
        }
        if(direction.equals("寻找更多地机遇")){
            nextRoom = currentRoom.getExit("寻找更多地机遇");

        }        if (nextRoom == null) {
            System.out.println("呵！又疯了一个，这可没有这种门");
        }
        else {
            currentRoom = nextRoom;
            System.out.println("你在" + currentRoom);
            System.out.print("出口有:\n");
            System.out.print(currentRoom.getExitdesc());
            System.out.println();
            new Hunting().start();
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Game game = new Game();
        game.printWelcome();
        new Hunting().start();
        while ( true ) {
            String line = in.nextLine();
            String[] words = line.split(" ");
            if ( words[0].equals("帮帮我") ) {
                game.printHelp();
            } else if (words[0].equals("进入") ) {
                game.goRoom(words[1]);
            } else if ( words[0].equals("别了您内") ) {
                break;
            }//else if ( words[0].equals("menu") ){
            //}
        }
        System.out.println("再来哦");
        in.close();
    }
}
